package com.yst.suivi.data.project;

import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;

import com.yst.suivi.data.AbstractEntityBean;
import com.yst.suivi.data.team.Team;
import com.yst.suivi.status.StatusConstants;

/**
 * @author stolf
 * @ejb.bean name="Project" type="CMP" cmp-version="2.x" schema="project"
 *           local-jndi-name="ProjectBean" view-type="local" primkey-field =
 *           "id" reentrant = "True"
 * @ejb.home generate="local"
 * @ejb.persistence table-name = "project"
 * @jboss.entity-command name = "key-generator"
 * @jboss.read-ahead eager-load-group = "most" strategy = "on-load"
 *                   page-size="25"
 * @jboss.load-group name="most"
 * @ejb.interface local-extends = "com.yst.suivi.data.util.NamedObject,
 *                javax.ejb.EJBLocalObject"
 * @ejb.finder signature="java.util.Collection findAll()" query="SELECT
 *             OBJECT(g) FROM project AS g" ejb.finder
 *             signature="java.util.Collection
 *             findByCdp(com.yst.suivi.data.user.User usr)" query="SELECT
 *             OBJECT(g) FROM project AS g WHERE g.cdp=?1 AND g.status=3"
 *             ejb.finder signature="java.util.Collection
 *             findByTeam(com.yst.suivi.data.user.User usr)" query="SELECT
 *             OBJECT(g) FROM project AS g, IN (g.users) AS equipe WHERE
 *             equipe=?1 AND g.status=3"
 * @ejb.finder signature="java.util.Collection
 *             findProjects(com.yst.suivi.data.contrats.Contrat contrat)"
 *             query="SELECT OBJECT(g) FROM project AS g, IN (g.contrats) AS C
 *             where C=?1"
 */
public abstract class ProjectBean extends AbstractEntityBean implements EntityBean
{
	/**
	 * @return
	 * @throws CreateException
	 * @ejb.create-method view-type = "local"
	 */
	public String ejbCreate() throws CreateException
	{
		setStatus(StatusConstants.OPEN);
		setRafFlag(0);
		setTypeProj(ProjectConstante.MODE_AT);
		return null;
	}

	public void ejbPostCreate()
	{
		// by default nothing to do
	}

	/**
	 * Return the primary key of the object
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.jdbc-type type = "VARCHAR"
	 * @jboss.sql-type type = "VARCHAR(255)"
	 */
	public abstract String getId();

	/**
	 * Fix the primary key of the object. The method should be used only by the
	 * container
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setId(String id);

	/**
	 * Return the name of the object
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 * @jboss.jdbc-type type = "VARCHAR"
	 * @jboss.sql-type type = "VARCHAR(255)"
	 */
	public abstract String getNom();

	/**
	 * Fix the name of the user. The method should be used only by the container
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setNom(String nom);

	/**
	 * Return the name of the object
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract String getCode();

	/**
	 * Fix the name of the user. The method should be used only by the container
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setCode(String code);

	/**
	 * Etat du projet. Selon l'etat, il peut etre plus ou moins modifiee
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract int getStatus();

	/**
	 * Positionne l'etat du projet
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setStatus(int status);

	/**
	 * Flag qui indique si le projet contient des activites avec un reste a
	 * faire a saisir
	 * <UL>
	 * <LI> 0 : RAF a saisir
	 * <LI> 1 : pas de RAF a saisir
	 * </UL>
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract int getRafFlag();

	/**
	 * Positionne l'etat du projet
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setRafFlag(int flag);

	/**
	 * Returns the list of the contrat for the project.
	 * 
	 * @ejb.relation name="contrat-projet" role-name = "ContratProjetRole"
	 *               target-multiple = "yes" target-ejb="Contrat"
	 * @jboss.relation-mapping style = "relation-table"
	 * @jboss.relation-table table-name = "LnkContratProject"
	 * @jboss.relation fk-column = "idProjet" related-pk-field = "id"
	 * @ejb.interface-method view-type="local"
	 * @return
	 */
	public abstract Collection getContrats();

	/**
	 * 
	 * @param contrats
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setContrats(Collection contrats);

	/**
	 * La methode lie le projet a une equipe. Ce principe permet d'affecter des
	 * droits sur un projet en fonction des membres de la team.
	 * 
	 * @return
	 * @ejb.relation name="team-projet" role-name = "TeamProjet"
	 *               target-role-name = "TeamProjetRole" target-multiple = "yes"
	 *               target-ejb="Team"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "teamId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract Team getTeam();

	/**
	 * La methode lie le projet avec une team
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setTeam(Team team);

	/**
	 * Flag qui indique le type du projet
	 * <UL>
	 * <LI> 0 : AT
	 * <LI> 1 : Forfait
	 * </UL>
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract int getTypeProj();

	/**
	 * Positionne l'etat du projet
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setTypeProj(int flag);
}
